//
//  TwoViewController.m
//  vc
//
//  Created by 杜超男 on 2019/3/19.
//  Copyright © 2019年 杜超男. All rights reserved.
//

#import "TwoViewController.h"
#import "Masonry.h"
#import "SmoothChartView.h"
#import "SmoothChartTwoView.h"
#import "BrokenChartView.h"
@interface TwoViewController ()<UIScrollViewDelegate>
{
    UIScrollView *sc; //滚动式图
    SmoothChartView *_smoothView;
    SmoothChartTwoView *_smoothTwoView;
    BrokenChartView *_brokenView;
    UIPageControl *pageC; //分页控制符
    NSArray *imgArr; //图片数组
    NSTimer *timer; //时间定时器
    int k; //计数
    UIView *backgroundView;
    UIView *backgroundView1;
    NSArray *DataSoure;
}

@end

@implementation TwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    DataSoure = @[@"集体活动" , @"吃饭睡觉" , @"集体活动" , @"吃饭睡觉" , @"集体活动" , @"吃饭睡觉" , @"集体活动" , @"回家"];
    //曲线的滚动视图  滚动View; and 滚动的豆豆;
    [self cvll];
    // 平滑曲线带阴影
    [self makeSmoothChartView];
    [self makeSmoothChartTwoView];
}
- (void)CloseBtnSome{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(BOOL)shouldAutorotate{
    return YES;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
//    return UIInterfaceOrientationMaskLandscapeLeft;
    return UIInterfaceOrientationMaskLandscapeRight;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
//    return UIInterfaceOrientationLandscapeLeft;
}
- (void)cvll{
    sc = [[UIScrollView alloc] initWithFrame:self.view.frame];
    //设置滚动式图的代理
    sc.delegate = self;
    //滚动范围
    sc.contentSize = CGSizeMake(self.view.frame.size.height*2+400, 0);
    //分页
    sc.pagingEnabled = YES;
    //弹簧
    sc.bounces = NO;
    //禁用水平滚动条
    sc.showsHorizontalScrollIndicator = NO;
    //view1--->专注曲线
    backgroundView = [[UIView alloc] initWithFrame:CGRectMake(60, 20, self.view.frame.size.height+100, self.view.frame.size.width-20)];
    backgroundView.backgroundColor = [UIColor whiteColor];
    //view2--->情绪曲线
    backgroundView1 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.height+270, 20, self.view.frame.size.height+100, self.view.frame.size.width-20)];
    backgroundView1.backgroundColor = [UIColor whiteColor];
    
    //把两个视图添加到滚动试图上
    [sc addSubview:backgroundView];
    [sc addSubview:backgroundView1];
    //把滚动试图添加到self.view 并且进行适配
    [self.view addSubview:sc];
    [sc mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(self.view.mas_safeAreaLayoutGuideLeft).inset(0);
        make.right.mas_equalTo(self.view.mas_safeAreaLayoutGuideRight).inset(0);
        
    }];
    //豆豆
    pageC = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.height-200)/2, 200, 200, 40)];
    //豆豆的数量
    pageC.numberOfPages = 2;
    //豆豆颜色
    //rgba(202/255.0, 202, 202, 1)
    pageC.pageIndicatorTintColor = [UIColor colorWithRed:202/255.0 green:202/255.0 blue:202/255.0 alpha:1];
    //rgba(100/255.0, 190/255.0, 83/255.0, 1)
    pageC.currentPageIndicatorTintColor = [UIColor colorWithRed:100/255. green:190/255.0 blue:83/255.0 alpha:1];
    //默认选中
    pageC.currentPage = 0;
    //将豆豆网滚动视图里加
    [self.view addSubview:pageC];
    [pageC mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(320);
        make.left.mas_equalTo(self.view.mas_safeAreaLayoutGuideLeft).inset((self.view.frame.size.width-200)/2);
        make.right.mas_equalTo(self.view.mas_safeAreaLayoutGuideRight).inset((self.view.frame.size.width-200)/2);
//        make.right.mas_equalTo(-(self.view.frame.size.width-200)/2);
        make.size.height.mas_equalTo(40);
    }];
}
//视图已经滚动的方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    pageC.currentPage = sc.contentOffset.x/self.view.frame.size.height;
    NSLog(@"%lf",sc.contentOffset.x);
}
#pragma mark - 专注曲线--->作图表
-(void)makeSmoothChartView{
    //    [self.view addSubview:backgroundView];
    //    backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
    
    //标题
    UILabel *TitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, self.view.bounds.size.height, 20)];
    TitleLabel.text = @"专注曲线";
    TitleLabel.textAlignment = NSTextAlignmentCenter;
    TitleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    [backgroundView addSubview: TitleLabel];
    UIButton *CloseBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.height - 40, 20, 20, 20)];
    [CloseBtn setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
    [CloseBtn addTarget:self action:@selector(CloseBtnSome) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:CloseBtn];
    
    for (int i = 0; i < 8; i ++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70*i+40, 240, 50, 20)];
        //rgba(226/255.0, 242/255.0, 223/255.0, 1)
        //rgba(254, 243, 211, 1)
        label.backgroundColor = [UIColor colorWithRed:226/255.0 green:242/255.0 blue:223/255.0 alpha:1];
        label.text = DataSoure[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:10];
        [backgroundView addSubview:label];
    }
    
    //平滑曲线图表
    _smoothView = [[SmoothChartView alloc] initWithFrame:CGRectMake(20, 40, (self.view.bounds.size.height-30),392/2)];
    //    _smoothView.layer.cornerRadius = 10;
    //    _smoothView.layer.masksToBounds = YES;
    _smoothView.backgroundColor = [UIColor whiteColor];
    //X轴刻度
    _smoothView.arrX = @[@"8:00",@"10:00",@"12:00" , @"14:00" , @"16:00" , @"18:00"];
    // Y轴刻度
    _smoothView.arrY = @[@"0",@"50",@"100"];
    [_smoothView refreshChartAnmition];
    NSArray *pathX = @[@"1",@"2.5",@"4",@"5.5",@"7",@"8.5" , @"10" , @"11.5" ,@"13"];
    NSArray *pathY = @[@"0",@"100",@"40",@"50",@"40",@"70",@"30" , @"60" , @"0"];
    [_smoothView drawSmoothViewWithArrayX:pathX andArrayY:pathY andScaleX:12.0];
    [backgroundView addSubview:_smoothView];
//    [backgroundView1 addSubview:_smoothView];
}
#pragma mark - 情绪曲线--->作图表
- (void)makeSmoothChartTwoView{
    //标题
    UILabel *TitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, self.view.bounds.size.height, 20)];
    TitleLabel.text = @"情绪曲线";
    TitleLabel.textAlignment = NSTextAlignmentCenter;
    TitleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    [backgroundView1 addSubview: TitleLabel];
    UIButton *CloseBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.height - 40, 20, 20, 20)];
    [CloseBtn setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
    [CloseBtn addTarget:self action:@selector(CloseBtnSome) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView1 addSubview:CloseBtn];
    
    for (int i = 0; i < 8; i ++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70*i+40, 240, 50, 20)];
        //rgba(226/255.0, 242/255.0, 223/255.0, 1)
        //rgba(254, 243, 211, 1)
        label.backgroundColor = [UIColor colorWithRed:254/255.0 green:243/255.0 blue:211/255.0 alpha:1];
        label.text = DataSoure[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:10];
        [backgroundView1 addSubview:label];
    }
    
    //平滑曲线图表
    _smoothTwoView = [[SmoothChartTwoView alloc] initWithFrame:CGRectMake(20, 40, (self.view.bounds.size.height-30),392/2)];
    //    _smoothView.layer.cornerRadius = 10;
    //    _smoothView.layer.masksToBounds = YES;
    _smoothView.backgroundColor = [UIColor whiteColor];
    //X轴刻度
    _smoothTwoView.arrX = @[@"8:00",@"10:00",@"12:00" , @"14:00" , @"16:00" , @"18:00"];
    // Y轴刻度
    _smoothTwoView.arrY = @[@"0",@"50",@"100"];
    [_smoothTwoView refreshChartAnmition];
    NSArray *pathX = @[@"1",@"2.5",@"4",@"5.5",@"7",@"8.5" , @"10" , @"11.5" ,@"13"];
    NSArray *pathY = @[@"0",@"100",@"40",@"50",@"40",@"70",@"30" , @"60" , @"0"];
    [_smoothTwoView drawSmoothViewWithArrayX:pathX andArrayY:pathY andScaleX:12.0];
    [backgroundView1 addSubview:_smoothTwoView];
}
@end
